package com.ourteam.education.api;

import org.apache.commons.lang3.StringUtils;

import com.ourteam.education.dao.StudentDAOQueryBean;
import com.ourteam.education.domain.StudentBean;
import com.ourteam.frame.web.AbstractSearchModel;

public class StudentSearchBean extends AbstractSearchModel<StudentDAOQueryBean> {

	private String studentName;

	private String contactsPhone;

	private String contactsName;

	public String getStudentName() {
		return studentName;
	}

	public void setStudentName(String studentName) {
		this.studentName = studentName;
	}

	public String getContactsPhone() {
		return contactsPhone;
	}

	public void setContactsPhone(String contactsPhone) {
		this.contactsPhone = contactsPhone;
	}

	public String getContactsName() {
		return contactsName;
	}

	public void setContactsName(String contactsName) {
		this.contactsName = contactsName;
	}

	@Override
	public String getMappedDAOField(String aProperty) {
		return StudentBean.getMappedDAOField(aProperty);
	}

	@Override
	protected void doBuildQueryBean(StudentDAOQueryBean queryBean) throws Exception {
		
		StudentDAOQueryBean.Criteria criteria = queryBean.createCriteria();
		
		if(StringUtils.isNoneBlank(this.studentName)) {
			criteria.andStudentNameLike(studentName);
		}
		
		if(StringUtils.isNoneBlank(this.contactsName)) {
			criteria.andContactsNameLike(contactsName);
		}
		
		if(StringUtils.isNoneBlank(this.contactsPhone)) {
			criteria.andContactsPhoneLike(contactsPhone);
		}
	}

}
